import java.util.Scanner;

import javax.swing.plaf.synth.SynthOptionPaneUI;

public class MistakeCheck {
    private static int student;
    private static String name;
    //private static double ChineseMark;
    //private static double MathMark;
    //private static double EnglishMark;

    public static void main(String[] args) throws NegativeMistake, MarkMistake {
        // 1. 判断输入的学生人数是不是整数和正数(2种：自带和自写)
        System.out.println("Please enter the number of the students.");
        Scanner input = new Scanner(System.in);
        NumberOfPeople.numJudge();
        student = NumberOfPeople.getNum();

        Scanner nameload = new Scanner(System.in);
        String[] name = new String[student];

        // 2. 判断数组是否越界（自带）
        double[][] score = new double[student][4];
        try {
            for (int i = 0; i < student; i++) {
                System.out.println("please enter the No." + (i + 1) + "'s name. " + "\t");
                name[i] = nameload.nextLine();

                // 3. 判断每科成绩是不是数值且是不是100分以内（自写）

                //@语文成绩
                System.out.println("please load in the Chinese score. " + "\t");
                try{
                    double a = input.nextDouble();
                    Mark.ChineseMarkJudge(a);
                }
                catch(Exception e){
                    System.out.println(e);
                }
                score[i][1] = Mark.getChineseMark();

                //@数学成绩
                System.out.println("please load in the Math score. " + "\t");
                try{
                    double b = input.nextDouble();
                    Mark.MathMarkJudge(b);
                }
                catch(Exception e){
                    System.out.println(e);
                }
                score[i][2] = Mark.getMathMark();

                //@英语成绩
                System.out.println("please load in the English score. " + "\t");
                try{
                    double c = input.nextDouble();
                    Mark.EnglishMarkJudge(c);
                }
                catch(Exception e){
                    System.out.println(e);
                }
                 
                double A = Mark.getEnglishMark();
                score[i][3] = A;
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println(e.getMessage());
        }

        float[] averageSTU = new float[student];
        int[] sumSTU = new int[student];
        for (int i = 0; i < student; i++) {
            for (int j = 1; j < score[i].length; j++) {
                sumSTU[i] += score[i][j];
                averageSTU[i] = sumSTU[i] / 3;
            }
            System.out.println("NAME" + "\t" + "CHINESE" + "\t" + "MATH" + "\t" + "ENGLISH" + "\t" + "AVERAGE" + "\t");
            System.out.print(name[i] + "\t" + score[i][1] + "\t" + score[i][2] + "\t" + score[i][3] + "\t"
                    + String.format("%.2f", averageSTU[i]) + "\t");
            System.out.println();
        }
        System.out.println("-------------------------------------------");
        System.out.print("Average" + "\t");
        int i;
        float[] averageSUB = new float[4];
        for (int j = 1; j < 4; j++) {
            float sumSUB = 0;
            for (i = 0; i < student; i++) {

                sumSUB += score[i][j];
            }
            averageSUB[j] = sumSUB / student;
            System.out.print(String.format("%.2f", averageSUB[j]) + "\t");
        }
        input.close();
    }
}
